package problems.knapsack;

public class CircleCreator extends KnapsackCreator {

	// Default suggested in:
	// "Where are the hard knapsack problems?"
	// David Pisinger
	// http://www.google.com/url?sa=t&ct=res&cd=2&url=http%3A%2F%2Fdiku.dk%2Fpublikationer%2Ftekniske.rapporter%2Frapporter%2F03-08.pdf&ei=kLZUR9SMK4jiiAHru8ndBg&usg=AFQjCNH2d04g47pCFKVxvjUwTnP4S5uCsg&sig2=KBaVFu1iqNktfRcdJhrxbg>
	private static final double DEFAULT_D = 2d / 3d;

	private double _d;

	public CircleCreator(int n, int R) {
		this(n, DEFAULT_D, R);
	}

	public CircleCreator(int n, double d, int R) {
		super(n, R);
		_d = d;
		createWeightsAndProfits(_weights, _profits);
		setInstanceNumber(1);
	}

	@Override
	protected void createWeightsAndProfits(int[] weights, double[] profits) {
		for (int i = 0; i < weights.length; i++) {
			weights[i] = (int) (Math.random() * _R);
			double a = 4d * Math.pow(_R, 2d);
			double b = Math.pow(weights[i] - 2d * _R, 2d);
			double c = _d * Math.sqrt(a - b);
			profits[i] = c;
		}
	}
}
